In [1]:
import numpy as np
In [3]:
import StringIO
In [15]:
x = StringIO.StringIO()
arr = np.arange(10)
np.savetxt(x,arr, header='test', comments="")
In [17]:
x.seek(0)
print(x.read())
with open('file.txt','w') as f:
f.write(x.getvalue())
In [19]:
%%bash
cat file.txt
How do you convolve fast?
see, e.g., http://keflavich.github.io/blog/fft-comparisons-in-python.html
In [20]:
from astropy.convolution import convolve, convolve_fft
Speed of DFT: $O(n^2)$
Speed of FFT: $O(n log(n))$
In [29]:
import scipy.fftpack, scipy.ndimage, scipy.signal
In [33]:
scipy.ndimage.convolve
scipy.signal.fftconvolve??
In [38]:
%%bash
factor 9216
faster fftw: --enable-avx
for "advanced vector instructions". 8x FLOPs at a time!
In [72]:
x = np.random.randn(64) + 5 + np.sin(np.arange(64))*3
In [73]:
f = np.fft.fft(x)
In [74]:
pl.plot(x)
Out[74]:
In [75]:
%matplotlib inline
import pylab as pl
pl.plot(np.abs(f))
Out[75]:
In [76]:
f[0] = 0
f[10] = 0
f[64-10] = 0
pl.plot(np.abs(f))
Out[76]:
In [77]:
xi = np.fft.ifft(f)
In [78]:
pl.plot(xi.real)
pl.plot(x)
Out[78]:
python setup.py develop
Use https://github.com/astropy/package-template to get everything set up in a cool way. develop
doesn't do much good for C code.
Within an interactive session, use reload(package)
(python2) or import importlib; importlib.reload(package)
to reload the package. This finnicky.
Other option, which works with C extensions: python setup.py build_ext --inplace
. Or you can use python setup.py build
to build into the build/
directory, which will then be accessible using import
if you've used python setup.py develop
In [80]:
%%bash
cd ~/repos/astropy
ls
ls build/
Profiling (tracking memory and time use) can be done with the memory_profile
and timeit
utilities. psrecord is also nice.
In [ ]: